package com.classroom.langchain.demo.controller;

import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {


//    http://localhost:8080/chat?message=东哥帅不帅


    @Autowired
    private OpenAiChatModel openAiChatModel;
    @RequestMapping("/chat1")
    public String chat(@RequestParam("message") String message) {
        if (message == null || message.isEmpty()) {
            return "Please provide a message";
        }
        try {
            String result = openAiChatModel.chat(message);
            return result;
        } catch (Exception e) {
            return "Error occurred: " + e.getMessage();
        }
    }

}